import 'package:flutter/cupertino.dart';

import 'package:flutter/material.dart';

class ScrollNotificationTestRoute extends StatefulWidget {
  @override
  ScrollNotificationTestRouteState createState() =>
      new ScrollNotificationTestRouteState();
}

class ScrollNotificationTestRouteState
    extends State<ScrollNotificationTestRoute> {
  String _progress = "0%";
  
  @override
  Widget build(BuildContext context) {
    return Scrollbar(
        child: NotificationListener<ScrollNotification>(
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          ListView.builder(
            itemBuilder: (context, index) {
              return ListTile(title: Text("$index"));
            },
            itemCount: 100,
            itemExtent: 50.0,
          ),
          CircleAvatar(
              radius: 30.0,
              child: Text(_progress),
              backgroundColor: Colors.black54)
        ],
      ),
      onNotification: (ScrollNotification notification) {
        double progress =
            notification.metrics.pixels / notification.metrics.maxScrollExtent;

//重新构建
        setState(() {
          _progress = "${(progress * 100).toInt()}%";
        });

        print("BottomEdge:${notification.metrics.extentAfter == 0}");
//return ture //放开此行注释后，进度条将失效
      },
    ));
  }
}
